package cn.swh.guguanjia.service.impl;

import cn.swh.guguanjia.entity.Qualification;
import cn.swh.guguanjia.entity.QualificationCondition;
import cn.swh.guguanjia.mapper.QualificationMapper;
import cn.swh.guguanjia.mapper.SysUserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.swh.guguanjia.entity.SysUser;
import cn.swh.guguanjia.service.QualificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class QualificationServicelmpl extends BaseServicelmpl<Qualification,Long> implements QualificationService {


    @Autowired
    QualificationMapper mapper;

    @Autowired
    SysUserMapper sysUserMapper;

    @Value("${staticPath}")
    String staticPath;

    @Override
    public PageInfo<Qualification> selectPage(int pageNum, int pageSize, QualificationCondition condition) {
        PageHelper.startPage(pageNum,pageSize);

        List<Qualification> qualifications = mapper.selectPage(condition);

        PageInfo<Qualification> pageInfo = new PageInfo<>(qualifications);
        return pageInfo;
    }

    @Override
    public Qualification selectByPrimaryKey(Long o) {
        Qualification qualification = super.selectByPrimaryKey(o);
        SysUser sysUser = sysUserMapper.selectByPrimaryKey(qualification.getUploadUserId());
        qualification.setAddress(staticPath+sysUser.getOfficeId()+"/"+qualification.getAddress());

        return qualification;
    }
}
